/*
 *  TabComponent.cpp
 *
 *  Created by David Rowland on 30/11/2008.
 *  Copyright 2008 UWE. All rights reserved.
 *
 */

#include "TabComponent.h"

TabComponent::TabComponent()
	: TabbedComponent(TabbedButtonBar::TabsAtTop)
{
	mainComponent = new MainComponent ();
	usageCodeComponent = new UsageCodeComp();
	
	setTabBarDepth (30);
	setIndent(5); 
	addTab (T("Main"), Colours::azure, mainComponent, true);
	addTab (T("Usage"), Colours::azure, usageCodeComponent, true);
	setCurrentTabIndex (0);
}

TabComponent::~TabComponent()
{
//	deleteAllChildren();
}

void TabComponent::resized()
{
	TabbedComponent::resized();
}

//==============================================================================

// Tab changed callback - this will refresh the usage code
void TabComponent::currentTabChanged (const int newCurrentTabIndex,
									  const String& newCurrentTabName)
{
	DBG_PRINTF(( T("Tab changed to '%s' at index %d "), 
				 (const char *)newCurrentTabName, 
				 newCurrentTabIndex ));
	
	if(newCurrentTabName == T("Usage"))
	{
		DBG_PRINTF(( T("Usage code component selected.") ));
		
		// Get the name from the user settings component
		String newFontName = mainComponent->userSettings->binaryFileName->getText();
		
		// Set up text to display in the text editor window
		String codeText;
		String resourceName = (newFontName + "::" + newFontName);
		String resourceSize = (newFontName + "::" + newFontName + "Size");
		
		codeText << "Font* " << newFontName << " = 0;\n"
		<< "MemoryInputStream fontStream (" << resourceName << ", " << resourceSize << ", false);\n"
		<< "Typeface* typeFace = new Typeface (fontStream);\n"
		<< newFontName << " = new Font (*typeFace);\n"
		<< newFontName << "->setHeight (10.0f);\n"
		<< "delete typeFace;";
				
		usageCodeComponent->generatedCode->setText(codeText);
	}
}